<link rel="stylesheet" href="__PUBLIC__/admin/css/bootstrap.css">
<style>
        .keyword h3{
            font-size: 20px;
            color: #101010;
            margin-bottom: 20px;
        }
        .keyword h3 span{
            color: #3F51B5;
            font-size: 14px;
            margin-left: 18px;
        }
        .keyword textarea{
            padding: 16px;
            width:100%; 
            min-height:300px; 
            resize:none;
            outline: none;
        }
        .keyword .right{
            float: right;
            margin-top: 30px;
        }
        .keyword .right button{
            width: 143px;
            height: 59px;
            line-height: 20px;
            border-radius: 4px;
            background-color: #6A6A6A;
            color: #fff;
            font-size: 14px;
            text-align: center;
            border: none;
            margin-left: 26px;
        }
        .kw-price-input{
            width: 70px;
            height: 30px;
        }
    </style>
<div class="content"> 
                <div class="keyword">
                    <form action="" method="POST">
                    <!-- <h3>关键词价格查询<span>单次查询最多20个关键词</span></h3> -->
                    <h3>关键词价格查询</h3>
                    <textarea placeholder="请添加你的关键词，多个关键词请用回车分割" name='keyword'>{$keyword}</textarea>
                    <div class="right" style="margin-bottom:70px;"> 
                        <button type="submit">立即查询</button>
                    </div>
                    </form>
                </div>
                <table class="table">
                    <tbody>
                    <tr>
                        <volist name="header" id="vo">
                            <th>{$vo}
                                <span>
                                    <a class="glyphicon glyphicon-triangle-top"></a>
                                    <a class="glyphicon glyphicon-triangle-bottom"></a>
                                </span>
                            </th>
                        </volist>
                    </tr>
                    <volist name="list" id="vo">
                        <tr class="kw-row">
                            <volist name="vo" id="v">
                                <eq name="key" value="id">
                                    <td style="display: none" data-field="{$key}" class="kw-col">{$v}</td>
                                    <else/>
                                    <td class="kw-col" data-field="{$key}">{$v}</td>
                                </eq>
                            </volist>
                        </tr>
                    </volist>

                    </tbody>
            </table>
            <div class="keyword">
                    <div class="right">
                        <button class="set-price">改价</button>
                        <button class="save-price">确定</button>
                        <button>导出</button>
                    </div>
                </div> 
            </div>
<script type="text/javascript">

    // set price
    $('.set-price').on('click', function(){

        // traversing row
        $('.kw-row').each(function(){

            // traversing col
            $(this).children('.kw-col').each(function(index){
                var text = $(this).text();
                var field = $(this).attr('data-field');

                if(index > 1){
                    $(this).html('<input class="kw-price-input" data-field="'+field+'" value="'+text+'">')
                } else {
                    $(this).append('<input type="hidden" class="kw-price-input" data-field="'+field+'" value="'+text+'">')
                }
            });
        });

    });

    // save price
    $('.save-price').on('click', function(){

        var price_list = [];
        // row
        $('.kw-row').each(function(i){

            price = [];
            // col
            $(this).find('.kw-price-input').each(function(){

                price.push($(this).val());

            });

            // ajax
            $.ajax({
                type:'post',
                traditional :true,
                url:'{:U("savePrice")}',
                data:{
                    'id':price[0],
                    'keyword':price[1],
                    'baiduipc':price[2],
                    'baiduim':price[3],
                    '360pc':price[4],
                    '360m':price[5],
                    'sogoupc':price[6],
                    'sogoum':price[7]
                },
                success:function(data,status){
                    if(status == 'success'){
                        if(data.err_code == 0){
                            location.reload();// restore set table
                        }
                    }

                }
            });
            price_list.push(price);

        });

    })
</script>